package logic

import (
	"context"
	"shopping/model/redis"
	"strconv"

	"shopping/shoprpc/internal/svc"
	"shopping/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductLikeListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductLikeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductLikeListLogic {
	return &ProductLikeListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductLikeListLogic) ProductLikeList(in *shoprpc.ProductLikeListRequest) (*shoprpc.ProductLikeListResponse, error) {
	// todo: add your logic here and delete this line

	srouce := redis.Client.ZRevRangeWithScores("productLike", 0, 9)

	var srouces []*shoprpc.LikeList
	for _, z := range srouce.Val() {

		list := &shoprpc.LikeList{
			Name: z.Member.(string),
			Like: strconv.Itoa(int(z.Score)),
		}
		srouces = append(srouces, list)
	}
	return &shoprpc.ProductLikeListResponse{List: srouces}, nil
}
